//编写老师的数据服务
const TeacherModel = require('../db/models/teacher');

class TeacherService {
  async addTeacherData(data){

    const tid = data.tid;
    //查询数据seq 中的findOne的方法
    const result = await TeacherModel.findOne({
        where: { tid }
    })
    
    if(result) {
        return await TeacherModel.update(data, {
          where: { tid }
        })
    }else {
         //create方法创建表数据seq
         return await TeacherModel.create(data)
    }
     
    }

    async getTeacherData () {
      return await TeacherModel.findAll({
        attributes: {
          exclude: ['tid', 'teacherImg']
        }
      });
    }
    async changeTeacherStatus (id, status) {
      const res = await TeacherModel.update({ status },{
        where: { id }
      })
      return res[0]
    }

   async selectStarTeacher (id, isStar) {
    const res = await TeacherModel.update({ isStar },{
      where: { id }
    })
    return res[0]
   }
}

module.exports = new TeacherService();